package com.googlecode.bip.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.naming.NamingException;
import com.googlecode.bip.dao.utils.Listable;
import com.googlecode.bip.entity.IQuestion;
import com.googlecode.bip.entity.Question;

/**
 *
 * @author Claude CHOISNET
 */
public abstract class QuestionDAO
        implements Listable<IQuestion>
{
    private static final long serialVersionUID = 1L;

    /**
     * Build QuestionDAO
     */
    protected QuestionDAO()
    {
    }

    @Override //Listable<IQuestion>
    public IQuestion newInstance(final ResultSet rSet )
        throws SQLException
    {
        return new Question().set( rSet );
    }

    /**
     *
     * @param idquestion
     * @param idlocal
     * @return
     * @throws NamingException
     * @throws SQLException
     */
    public abstract IQuestion findQuestion( int idquestion, String idlocal )
       throws NamingException, SQLException;

    /**
     *
     * @param idquestion
     * @return
     * @throws NamingException
     * @throws SQLException
     */
    public abstract List<IQuestion> findQuestions( int idquestion )
      throws NamingException, SQLException;

    /**
     * List of questions for a specified topic and idlocal
     * @param idtopic Topic id
     * @param idlocal Local id
     * @return a List of IQuestion
     * @throws SQLException if any
     * @throws NamingException if any
     */
    public abstract List<IQuestion> findQuestions( int idtopic, String idlocal )
       throws SQLException, NamingException;

    /**
     * List of idquestion for a specified topic
     * @param idtopic Topic id
     * @return a List of IQuestion
     * @throws SQLException if any
     * @throws NamingException if any
     */
    public abstract List<Integer> _tmp_findQuestions( int idtopic )
       throws SQLException, NamingException;

   /**
    * Insert a new Question (must not exist)
    * <br/>
    * {@link IQuestion#getIdQuestion()} value is ignored by insertion (must be equal 0)
    * <br/>
    * After database insert this method update {@link IQuestion#getIdQuestion()} content
    * with the index created by database.
    *
    * @param iquestion IQuestion to add in database
    * @return true if insert succeed
    * @throws NamingException
    * @throws SQLException
    */
   public abstract boolean insertQuestion( final IQuestion iquestion )
       throws NamingException, SQLException;

   /**
    *
    * @param idquestion
    * @return
    * @throws NamingException
    * @throws SQLException
    */
   public abstract boolean deleteQuestion( final int idquestion )
       throws NamingException, SQLException;

   /**
    *
    * @param iquestion
    * @return
    * @throws NamingException
    * @throws SQLException
    */
   public abstract boolean updateQuestion( final IQuestion iquestion )
       throws NamingException, SQLException;

}

